/*
 * @Author: hmhvictory 1400628624@qq.com
 * @Date: 2025-07-24 16:24:18
 * @LastEditors: hmhvictory 1400628624@qq.com
 * @LastEditTime: 2025-07-24 16:24:41
 * @FilePath: \实训笔记\day09\demo5.java
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
package day09;
public class demo5 {
    public static void main(String[] args) {
        // 示例调用
        System.out.println(getNum("sum", 1, 2, 3, 4, 5));
        System.out.println(getNum("avg", 2, 4, 6));
        System.out.println(getNum("max", 10, 20, 5, 30));
        System.out.println(getNum("min", 5, 2, 8, 1));
        System.out.println(getNum("sum"));
    }

    public static double getNum(String type, int... numbers) {
        // 处理空参数集
        if (numbers.length == 0) {
            return 0;
        }

        double result = 0;

        switch (type) {
            case "sum":
                for (int num : numbers) {
                    result += num;
                }
                System.out.print("总和是：");
                break;
            case "avg":
                int sum = 0;
                for (int num : numbers) {
                    sum += num;
                }
                result = (double) sum / numbers.length;
                System.out.print("平均值是：");
                break;
            case "max":
                result = numbers[0];
                for (int num : numbers) {
                    if (num > result) {
                        result = num;
                    }
                }
                System.out.print("最大值是：");
                break;
            case "min":
                result = numbers[0];
                for (int num : numbers) {
                    if (num < result) {
                        result = num;
                    }
                }
                System.out.print("最小值是：");
                break;
            default:
                System.out.println("不支持的操作类型");
                return 0;
        }

        return result;
    }
}